package com.mvc.framework.web;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mvc.framework.FrameworkConstants;
import com.mvc.framework.service.HistoryRecordManager;

@Controller
@RequestMapping("/historyRecord")
public class HistoryRecordController {
	@Autowired
	private HistoryRecordManager historyRecordManager;
	@RequestMapping("/page")
	public String page(HttpServletRequest request,ModelMap modelMap){
		Map<String,Long> maps = historyRecordManager.getAllModelHistoryRecordCount();
		modelMap.addAttribute("maps", maps);
		return "framework/listHistoryRecord";
	}

	@RequestMapping("/delete/{tableName}")
	public String delete(HttpServletRequest request,ModelMap modelMap,@PathVariable String tableName){
		historyRecordManager.deleteHistoryRecordByTableName(tableName,null);
		request.setAttribute(FrameworkConstants.MESSAGE, "操作成功");
		return page(request, modelMap);
	}

	@RequestMapping("/deleteAll")
	public String deleteAll(HttpServletRequest request,ModelMap modelMap,Date endDate){
		historyRecordManager.deleteAllHistoryRecord(endDate);
		request.setAttribute(FrameworkConstants.MESSAGE, "操作成功");
		return page(request, modelMap);
	}
}
